var mysql=require("mysql");

var connectionPool=null;

module.exports={
    init:function(host,user,password,database){
        connectionPool=mysql.createPool();
    },
    query:function(sql,obj,cb){
      var conn=  mysql.createConnection({
            host:obj.host,
            user:obj.user,
            password:obj.password,
            database:obj.database
        });
        conn.query(sql,function(error,results,fields){
            if(error){
                console.log(error);
                return;
            }
            cb(results,fields)
        })
        conn.end();
    },
    destory:function(){
        if(connectionPool!=null){
            connectionPool.end();
        }
    }

}